<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>javascript study</title>
    </head>
    <body>
        <script >
        function checkvalid(){
            var fname = document.forms["myform"]["fname"].value;
            if(fname == null || fname == ""){
                alert("输入字句为空")
                return false;
            }

        }
        </script>
        <form name="myform" action="#"  onsubmit="checkvalid()" method="GET">
            名字：<input type="text" name="fname">
            <input type="submit" value="提交">
        </form>
        <form action="demo.js" method="post">
            <input type="text" name="fname" required="required">
            <input type="submit" value="提交">
        </form>
    </body>
</html>